<template>
  <div>
    <VolBox
      :lazy="true"
      :model.sync="model"
      title="添加详情"
      :height="400"
      :width="800"
      :padding="15"
    >
      <vol-form
        ref="form"
        :formRules="editFormOptions"
        :formFields="editFormFields"
        :editor="editor"
      ></vol-form>
      <div slot="footer">
        <Button type="success" @click="getFirstRow">保存</Button>
        <Button type="info" @click="close">关闭</Button>
      </div>
    </VolBox>

    <VolBox :lazy="true" :model.sync="model2" title="产品拉取">
      <vol-form
        ref="form"
        :formRules="editFormOptions2"
        :formFields="editFormFields2"
      ></vol-form>
      <div slot="footer">
        <Button type="success" @click="getPullRow">保存</Button>
        <Button type="info" @click="model2 = false">关闭</Button>
      </div>
    </VolBox>
  </div>
</template>
<script>
export default {
  data() {
    return {
      list: [],
      type: "",
      editFormFields: {
        code: "",
        title: "",
        content: "",
        id: "",
        text_Type: "",
        createDate: "",
        createID: "",
        modifyDate: "",
        creator: "",
        modifier: "",
        merchantCode: "",
        merchantName: "",
      },
      editFormOptions: [
        [
          { title: "标题", field: "title", type: "text" },
          { title: "编码", field: "code", type: "text", hidden: true },
        ],
        [
          {
            title: "富文本内容",
            field: "content",
            type: "editor",
            colSize: 12,
          },
        ],
      ],
      goodName: "",
      //   表格
      //   isSingle: true,
      tableData: [],
      //   弹框
      model: false,
      editor: {
        uploadImgUrl: "/api/Products/Upload",
      },
      model2: false,
      editFormFields2: { supplierCode: "" },
      editFormOptions2: [
        [
          {
            dataKey: "",
            data: [],
            title: "供应商",
            required: true,
            field: "supplierCode",
            type: "select",
          },
        ],
      ],
    };
  },
  components: {
    VolBox: () => import("@/components/basic/VolBox.vue"),
    VolForm: () => import("@/components/basic/VolForm.vue"),
  },
  methods: {
    getPullRow() {
      let parmas = {
        SupplierID: this.editFormFields2.supplierCode,
      };
      this.http.get("/api/proPull/Pulling_product", parmas).then((reslut) => {
        if (reslut.status) {
          this.model2 = false;
          this.$Message.success('拉取成功');
        } else {
          this.$Message.error(reslut.message);
        }
      });
    },
    // 保存按钮
    getFirstRow() {
      if (!this.editFormFields.title) {
        this.$Message.error("请输入详情标题");
        return;
      }
      if (!this.editFormFields.content) {
        this.$Message.error("请输入详情内容");
        return;
      }
      this.editFormFields.code = this.base.chineseToPinYin(
        this.editFormFields.title
      );
      this.http
        .post("api/Texts/Add", { mainData: this.editFormFields }, true)
        .then((reslut) => {
          if (reslut.status) {
            //console.log(reslut.data);
            this.$store.getters
              .data()
              .addproducttext.submit(this.editFormFields);
            //this.$emit("submit",this.editFormFields);
            this.model = false;
          }
        });
    },
    // 关闭按钮
    close() {
      this.model = false;
    },
    open(type) {
      console.log(type);
      this.editFormFields.text_Type = type[0];
      this.model = true;
    },
    open2() {
      this.model2 = true;
      this.http
        .post("/api/Dictionary/GetVueDictionary", ["mall_supplier"])
        .then((res) => {
          this.distributorList = [];
          res.forEach((o) => {
            if (o.dicNo == "mall_supplier") {
              this.editFormOptions2[0][0].data = o.data;
            }
          });
        });
    },
  },
};
</script>
<style lang="less" scoped>
.el-cascader {
  line-height: 32px !important;
}
.el-input__inner {
  height: 32px !important;
}
</style>
